﻿namespace CometDocs
{
    /// <summary>
    /// Represents a conversion type from a file format to another.
    /// </summary>
    public class ConversionType
    {
        /// <summary>
        /// The original file format: e.g. for "PDF2XLS" From is "PDF".
        /// </summary>
        public string From { get; set; }

        /// <summary>
        /// The destination file format: e.g. for "PDF2XLS" To is "XLS".
        /// </summary>
        public string To { get; set; }

        public ConversionType(string from, string to)
        {
            From = from;
            To = to;
        }

        public override int GetHashCode()
        {
            return ToString().GetHashCode();
        }

        public override bool Equals(object obj)
        {
            ConversionType other = obj as ConversionType;

            return other != null && other.ToString() == this.ToString();
        }

        public override string ToString()
        {
            return From + "2" + To;
        }

        public static ConversionType FromString(string s)
        {
            string[] tokens = s.Split('2');

            return new ConversionType(tokens[0], tokens[1]);
        }
    }
}
